```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>线程顺序控制 - 技术小馆</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', 'Noto Serif SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #6e8efb 0%, #a777e3 100%);
        }
        .code-block {
            background: #282c34;
            border-radius: 8px;
            position: relative;
        }
        .code-header {
            background: #1e2227;
            border-top-left-radius: 8px;
            border-top-right-radius: 8px;
            padding: 8px 16px;
            color: #abb2bf;
            font-family: monospace;
            font-size: 14px;
            display: flex;
            align-items: center;
        }
        .code-dots {
            display: flex;
            margin-right: 12px;
        }
        .code-dot {
            width: 12px;
            height: 12px;
            border-radius: 50%;
            margin-right: 6px;
        }
        .code-red { background: #ff5f56; }
        .code-yellow { background: #ffbd2e; }
        .code-green { background: #27c93f; }
        .code-content {
            padding: 16px;
            overflow-x: auto;
            color: #abb2bf;
            font-family: monospace;
        }
        .section-divider {
            position: relative;
            height: 80px;
            overflow: hidden;
        }
        .wave-divider {
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            overflow: hidden;
            line-height: 0;
        }
        .wave-divider svg {
            position: relative;
            display: block;
            width: calc(100% + 1.3px);
            height: 80px;
        }
        .wave-divider .shape-fill {
            fill: #FFFFFF;
        }
        .method-card {
            transition: all 0.3s ease;
            border-radius: 12px;
            overflow: hidden;
            box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
        }
        .method-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .mermaid {
            background: white;
            border-radius: 8px;
            padding: 20px;
            margin: 20px 0;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white">
        <div class="container mx-auto px-6 py-20 md:py-32">
            <div class="max-w-3xl mx-auto text-center">
                <h1 class="text-4xl md:text-5xl font-bold mb-6">线程顺序控制的艺术</h1>
                <p class="text-xl md:text-2xl opacity-90 mb-8">探索多线程环境下的精确执行顺序控制方法</p>
                <div class="flex justify-center space-x-4">
                    <a href="#methods" class="px-6 py-3 bg-white text-purple-700 font-medium rounded-full hover:bg-gray-100 transition duration-300">
                        <i class="fas fa-code mr-2"></i> 查看方法
                    </a>
                    <a href="#diagram" class="px-6 py-3 bg-transparent border-2 border-white text-white font-medium rounded-full hover:bg-white hover:text-purple-700 transition duration-300">
                        <i class="fas fa-project-diagram mr-2"></i> 查看图表
                    </a>
                </div>
            </div>
        </div>
    </section>

    <!-- Wave Divider -->
    <div class="section-divider">
        <div class="wave-divider">
            <svg data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 120" preserveAspectRatio="none">
                <path d="M321.39,56.44c58-10.79,114.16-30.13,172-41.86,82.39-16.72,168.19-17.73,250.45-.39C823.78,31,906.67,72,985.66,92.83c70.05,18.48,146.53,26.09,214.34,3V0H0V27.35A600.21,600.21,0,0,0,321.39,56.44Z" class="shape-fill"></path>
            </svg>
        </div>
    </div>

    <!-- Introduction Section -->
    <section class="py-12 md:py-20 bg-white">
        <div class="container mx-auto px-6 max-w-4xl">
            <div class="mb-12">
                <h2 class="text-3xl font-bold text-gray-800 mb-6">线程执行顺序的挑战</h2>
                <p class="text-gray-600 leading-relaxed mb-6">
                    线程的执行顺序受操作系统的线程调度器控制，无法由线程本身直接控制。线程的调度是由操作系统内核根据各线程的优先级和调度算法决定的，因此无法预先确定哪个线程会先执行。
                </p>
                <p class="text-gray-600 leading-relaxed">
                    要控制线程的执行顺序，通常需要使用同步机制，如锁、条件变量等，来协调各线程之间的执行顺序。通过这些机制，可以实现线程的等待和唤醒，从而达到控制线程执行顺序的目的。
                </p>
            </div>

            <div class="mb-12 bg-yellow-50 border-l-4 border-yellow-400 p-4 rounded">
                <div class="flex">
                    <div class="flex-shrink-0">
                        <svg class="h-5 w-5 text-yellow-400" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
                            <path fill-rule="evenodd" d="M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z" clip-rule="evenodd" />
                        </svg>
                    </div>
                    <div class="ml-3">
                        <p class="text-sm text-yellow-700">
                            下面的代码运行3次后发现每次运行线程的顺序都不一样，这证明了线程执行的不可预测性。
                        </p>
                    </div>
                </div>
            </div>

            <div class="mb-12">
                <img src="https://cdn.nlark.com/yuque/0/2022/png/21449790/1660266954459-ab5b4623-38b6-4213-a2b6-969c314d513e.png" alt="线程执行顺序示例" class="rounded-lg shadow-md w-full">
            </div>
        </div>
    </section>

    <!-- Methods Section -->
    <section id="methods" class="py-12 md:py-20 bg-gray-50">
        <div class="container mx-auto px-6 max-w-6xl">
            <h2 class="text-3xl font-bold text-center text-gray-800 mb-12">线程顺序控制方法</h2>
            
            <!-- Method 1: Thread Pool -->
            <div class="method-card bg-white mb-12">
                <div class="p-6 md:p-8">
                    <div class="flex items-center mb-4">
                        <div class="bg-purple-100 p-3 rounded-full mr-4">
                            <i class="fas fa-server text-purple-600 text-xl"></i>
                        </div>
                        <h3 class="text-2xl font-bold text-gray-800">1. 使用线程池</h3>
                    </div>
                    <p class="text-gray-600 mb-6">
                        在使用线程池时，可以通过适当配置线程池的参数和任务提交顺序来间接控制线程的执行顺序。
                    </p>
                    <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1711854591031-67ed4474-787c-40a8-b853-51acca8355bc.png" alt="线程池示例" class="rounded-lg mb-6 w-full">
                    
                    <div class="grid md:grid-cols-2 gap-6 mb-6">
                        <div>
                            <h4 class="font-semibold text-gray-800 mb-2 flex items-center">
                                <i class="fas fa-check-circle text-green-500 mr-2"></i> 核心线程数和任务队列
                            </h4>
                            <p class="text-gray-600">
                                通过合理设置线程池的核心线程数和任务队列类型，可以影响线程的执行顺序。如果使用有界的任务队列（如<code>LinkedBlockingQueue</code>），则任务将按照提交的顺序进行执行。
                            </p>
                        </div>
                        <div>
                            <h4 class="font-semibold text-gray-800 mb-2 flex items-center">
                                <i class="fas fa-check-circle text-green-500 mr-2"></i> 任务提交顺序
                            </h4>
                            <p class="text-gray-600">
                                在向线程池提交任务时，可以按照特定的顺序提交任务，从而影响线程的执行顺序。通过合理控制任务的提交顺序，可以保证线程按照期望的顺序执行。
                            </p>
                        </div>
                    </div>

                    <div class="code-block mb-6">
                        <div class="code-header">
                            <div class="code-dots">
                                <span class="code-dot code-red"></span>
                                <span class="code-dot code-yellow"></span>
                                <span class="code-dot code-green"></span>
                            </div>
                            <span>ThreadPoolOrderExample.java</span>
                        </div>
                        <div class="code-content">
                            <pre><code>import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadPoolOrderExample {
    public static void main(String[] args) {
        ExecutorService executor = Executors.newFixedThreadPool(2); // 创建固定大小为2的线程池

        // 提交任务，按照指定顺序执行
        executor.submit(() -> {
            System.out.println("Task 1 executed");
        });
        executor.submit(() -> {
            System.out.println("Task 2 executed");
        });
        executor.submit(() -> {
            System.out.println("Task 3 executed");
        });

        executor.shutdown(); // 关闭线程池
    }
}</code></pre>
                        </div>
                    </div>
                    
                    <div class="bg-blue-50 p-4 rounded-lg border border-blue-200">
                        <h4 class="font-semibold text-blue-800 mb-2 flex items-center">
                            <i class="fas fa-info-circle text-blue-500 mr-2"></i> 关键点
                        </h4>
                        <p class="text-blue-700">
                            线程池使用<code>newFixedThreadPool(2)</code>方法创建了一个固定大小为2的线程池。然后，按照顺序提交了三个任务，由于线程池大小为2，因此只能有两个任务同时执行，而第三个任务会等待前面的任务执行完毕后再执行，从而保证了线程的出场顺序。
                        </p>
                    </div>
                </div>
            </div>

            <!-- Method 2: Lock -->
            <div class="method-card bg-white mb-12">
                <div class="p-6 md:p-8">
                    <div class="flex items-center mb-4">
                        <div class="bg-blue-100 p-3 rounded-full mr-4">
                            <i class="fas fa-lock text-blue-600 text-xl"></i>
                        </div>
                        <h3 class="text-2xl font-bold text-gray-800">2. 使用锁或同步机制</h3>
                    </div>
                    <p class="text-gray-600 mb-6">
                        通过使用锁或同步机制，可以实现线程的有序执行。具体而言，可以借助<code>ReentrantLock</code>或<code>Synchronized</code>关键字来实现线程的互斥访问和协调执行。
                    </p>
                    <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1711854685041-aec470d9-3354-4381-a011-c2db77c5895a.png" alt="锁机制示例" class="rounded-lg mb-6 w-full">

                    <div class="code-block mb-6">
                        <div class="code-header">
                            <div class="code-dots">
                                <span class="code-dot code-red"></span>
                                <span class="code-dot code-yellow"></span>
                                <span class="code-dot code-green"></span>
                            </div>
                            <span>ThreadOrderUsingLock.java</span>
                        </div>
                        <div class="code-content">
                            <pre><code>import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class ThreadOrderUsingLock {
    private static Lock lock = new ReentrantLock();
    private static int count = 1;

    public static void main(String[] args) {
        Thread thread1 = new Thread(() -> printNumber(1));
        Thread thread2 = new Thread(() -> printNumber(2));
        Thread thread3 = new Thread(() -> printNumber(3));

        thread1.start();
        thread2.start();
        thread3.start();
    }

    private static void printNumber(int number) {
        lock.lock();
        try {
            while (count != number) {
                try {
                    lock.wait(); // 当前线程等待，直到轮到自己执行
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("Thread " + number + " executed");
            count++;
            lock.notifyAll(); // 唤醒其他等待的线程
        } finally {
            lock.unlock();
        }
    }
}</code></pre>
                        </div>
                    </div>
                    
                    <div class="bg-blue-50 p-4 rounded-lg border border-blue-200">
                        <h4 class="font-semibold text-blue-800 mb-2 flex items-center">
                            <i class="fas fa-info-circle text-blue-500 mr-2"></i> 关键点
                        </h4>
                        <p class="text-blue-700">
                            我们使用<code>ReentrantLock</code>来创建一个锁，并在<code>printNumber()</code>方法中使用<code>lock</code>来保证线程的互斥访问。在每个线程开始执行时，首先获取锁，然后判断当前轮到的线程是否是自己，如果不是，则调用<code>wait()</code>方法使当前线程等待，直到轮到自己执行；如果是，则打印输出，并将<code>count</code>递增，最后调用<code>notifyAll()</code>方法唤醒其他等待的线程。通过这种方式，可以保证线程按照期望的顺序执行。
                        </p>
                    </div>
                </div>
            </div>

            <!-- Method 3: Thread Communication -->
            <div class="method-card bg-white mb-12">
                <div class="p-6 md:p-8">
                    <div class="flex items-center mb-4">
                        <div class="bg-green-100 p-3 rounded-full mr-4">
                            <i class="fas fa-comments text-green-600 text-xl"></i>
                        </div>
                        <h3 class="text-2xl font-bold text-gray-800">3. 使用线程间的通信机制</h3>
                    </div>
                    <p class="text-gray-600 mb-6">
                        通过线程间的通信机制，例如使用<code>wait()</code>和<code>notify()</code>方法或者<code>Condition</code>接口，可以实现线程的有序执行。具体而言，可以使用这些机制来控制线程的等待和唤醒，从而确保线程按照期望的顺序执行。
                    </p>
                    <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1711854732632-13c2353e-5eaa-4d0a-8976-379c257897ea.png" alt="线程通信示例" class="rounded-lg mb-6 w-full">

                    <div class="code-block mb-6">
                        <div class="code-header">
                            <div class="code-dots">
                                <span class="code-dot code-red"></span>
                                <span class="code-dot code-yellow"></span>
                                <span class="code-dot code-green"></span>
                            </div>
                            <span>ThreadOrderUsingThreadCommunication.java</span>
                        </div>
                        <div class="code-content">
                            <pre><code>public class ThreadOrderUsingThreadCommunication {
    private static final Object lock = new Object();
    private static int count = 1;

    public static void main(String[] args) {
        Thread thread1 = new Thread(() -> printNumber(1));
        Thread thread2 = new Thread(() -> printNumber(2));
        Thread thread3 = new Thread(() -> printNumber(3));

        thread1.start();
        thread2.start();
        thread3.start();
    }

    private static void printNumber(int number) {
        synchronized (lock) {
            while (count != number) {
                try {
                    lock.wait(); // 当前线程等待，直到轮到自己执行
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("Thread " + number + " executed");
            count++;
            lock.notifyAll(); // 唤醒其他等待的线程
        }
    }
}</code></pre>
                        </div>
                    </div>
                    
                    <div class="bg-blue-50 p-4 rounded-lg border border-blue-200">
                        <h4 class="font-semibold text-blue-800 mb-2 flex items-center">
                            <i class="fas fa-info-circle text-blue-500 mr-2"></i> 关键点
                        </h4>
                        <p class="text-blue-700">
                            我们使用了<code>wait()</code>和<code>notifyAll()</code>方法来实现线程的等待和唤醒。每个线程在开始执行时，首先获得锁对象<code>lock</code>的监视器，然后判断当前轮到的线程是否是自己，如果不是，则调用<code>wait()</code>方法使当前线程等待，直到轮到自己执行；如果是，则打印输出，并将<code>count</code>递增，最后调用<code>notifyAll()</code>方法唤醒其他等待的线程。通过这种方式，可以保证线程按照期望的顺序执行。
                        </p>
                    </div>
                </div>
            </div>

            <!-- Method 4: Priority Queue -->
            <div class="method-card bg-white mb-12">
                <div class="p-6 md:p-8">
                    <div class="flex items-center mb-4">
                        <div class="bg-indigo-100 p-3 rounded-full mr-4">
                            <i class="fas fa-sort-amount-up text-indigo-600 text-xl"></i>
                        </div>
                        <h3 class="text-2xl font-bold text-gray-800">4. 使用有序集合或队列</h3>
                    </div>
                    <p class="text-gray-600 mb-6">
                        使用有序集合或队列可以实现线程的有序执行。具体而言，可以使用<code>PriorityQueue</code>、<code>LinkedBlockingQueue</code>等数据结构来存储线程任务，并保证线程按照一定的顺序从集合或队列中取出执行。
                    </p>

                    <div class="code-block mb-6">
                        <div class="code-header">
                            <div class="code-dots">
                                <span class="code-dot code-red"></span>
                                <span class="code-dot code-yellow"></span>
                                <span class="code-dot code-green"></span>
                            </div>
                            <span>ThreadOrderUsingPriorityQueue.java</span>
                        </div>
                        <div class="code-content">
                            <pre><code>import java.util.PriorityQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadOrderUsingPriorityQueue {
    private static PriorityQueue<RunnableTask> taskQueue = new PriorityQueue<>();

    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(3);
        
        // 添加任务到优先队列，按照指定的顺序排序
        taskQueue.offer(new RunnableTask(1));
        taskQueue.offer(new RunnableTask(2));
        taskQueue.offer(new RunnableTask(3));

        // 依次执行任务
        while (!taskQueue.isEmpty()) {
            executorService.execute(taskQueue.poll());
        }

        executorService.shutdown();
    }

    static class RunnableTask implements Runnable, Comparable<RunnableTask> {
        private int order;

        public RunnableTask(int order) {
            this.order = order;
        }

        @Override
        public void run() {
            System.out.println("Thread " + order + " executed");
        }

        @Override
        public int compareTo(RunnableTask other) {
            return Integer.compare(this.order, other.order);
        }
    }
}</code></pre>
                        </div>
                    </div>
                    
                    <div class="bg-blue-50 p-4 rounded-lg border border-blue-200">
                        <h4 class="font-semibold text-blue-800 mb-2 flex items-center">
                            <i class="fas fa-info-circle text-blue-500 mr-2"></i> 关键点
                        </h4>
                        <p class="text-blue-700">
                            我们使用<code>PriorityQueue</code>来存储线程任务，并自定义<code>RunnableTask</code>类实现<code>Runnable</code>接口，并实现<code>Comparable</code>接口，以便按照指定的顺序排序。然后，我们将任务添加到优先队列中，优先队列会自动按照任务的顺序排序。最后，我们使用线程池依次执行优先队列中的任务，从而保证线程按照期望的顺序执行。
                        </p>
                    </div>
                </div>
            </div>

            <!-- Method 5: Concurrency Tools -->
            <div class="method-card bg-white">
                <div class="p-6 md:p-8">
                    <div class="flex items-center mb-4">
                        <div class="bg-red-100 p-3 rounded-full mr-4">
                            <i class="fas fa-tools text-red-600 text-xl"></i>
                        </div>
                        <h3 class="text-2xl font-bold text-gray-800">5. 使用并发工具类</h3>
                    </div>
                    <p class="text-gray-600 mb-6">
                        通过并发工具类可以实现线程的有序执行。例如，可以使用<code>CountDownLatch</code>、<code>CyclicBarrier</code>、<code>Semaphore</code>等工具类来控制线程的执行顺序。
                    </p>

                    <div class="code-block mb-6">
                        <div class="code-header">
                            <div class="code-dots">
                                <span class="code-dot code-red"></span>
                                <span class="code-dot code-yellow"></span>
                                <span class="code-dot code-green"></span>
                            </div>
                            <span>ThreadOrderUsingCountDownLatch.java</span>
                        </div>
                        <div class="code-content">
                            <pre><code>import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadOrderUsingCountDownLatch {
    private static CountDownLatch latch = new CountDownLatch(2); // 初始值为2，表示有两个线程需要等待

    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(3);

        // 线程A
        executorService.execute(() -> {
            System.out.println("Thread A executed");
            latch.countDown(); // 减少计数器
        });

        // 线程B
        executorService.execute(() -> {
            try {
                latch.await(); // 等待计数器归零
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("Thread B executed");
        });

        // 线程C
        executorService.execute(() -> {
            try {
                latch.await(); // 等待计数器归零
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            console.log("Thread C executed");
        });

        executorService.shutdown();
    }
}</code></pre>
                        </div>
                    </div>
                    
                    <div class="bg-blue-50 p-4 rounded-lg border border-blue-200">
                        <h4 class="font-semibold text-blue-800 mb-2 flex items-center">
                            <i class="fas fa-info-circle text-blue-500 mr-2"></i> 关键点
                        </h4>
                        <p class="text-blue-700">
                            我们使用<code>CountDownLatch</code>来实现线程的有序执行。线程A会立即执行，而线程B和线程C则需要等待线程A执行完毕后才能执行。通过<code>CountDownLatch</code>的<code>await()</code>和<code>countDown()</code>方法，我们可以控制线程的出场顺序。
                        </p>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Diagram Section -->
    <section id="diagram" class="py-12 md:py-20 bg-white">
        <div class="container mx-auto px-6 max-w-4xl">
            <h2 class="text-3xl font-bold text-center text-gray-800 mb-12">线程顺序控制方法对比</h2>
            
            <div class="mermaid">
                graph TD
                    A[线程顺序控制方法] --> B[线程池]
                    A --> C[锁机制]
                    A --> D[线程通信]
                    A --> E[有序队列]
                    A --> F[并发工具]
                    
                    B --> B1[固定大小线程池]
                    B --> B2[任务队列顺序]
                    
                    C --> C1[ReentrantLock]
                    C --> C2[Synchronized]
                    
                    D --> D1[wait/notify]
                    D --> D2[Condition]
                    
                    E --> E1[PriorityQueue]
                    E --> E2[LinkedBlockingQueue]
                    
                    F --> F1[CountDownLatch]
                    F --> F2[CyclicBarrier]
                    F --> F3[Semaphore]
                    
                    style A fill:#6e8efb,color:white,stroke:#333
                    style B fill:#a777e3,color:white,stroke:#333
                    style C fill:#6e8efb,color:white,stroke:#333
                    style D fill:#a777e3,color:white,stroke:#333
                    style E fill:#6e8efb,color:white,stroke:#333
                    style F fill:#a777e3,color:white,stroke:#333
            </div>

            <div class="mt-12 bg-gray-50 p-6 rounded-lg">
                <h3 class="text-2xl font-bold text-gray-800 mb-4">方法选择指南</h3>
                <div class="grid md:grid-cols-2 gap-6">
                    <div>
                        <h4 class="font-semibold text-gray-800 mb-2 flex items-center">
                            <i class="fas fa-check-circle text-green-500 mr-2"></i> 简单顺序控制
                        </h4>
                        <p class="text-gray-600">
                            对于简单的线程顺序控制，使用<code>CountDownLatch</code>或<code>wait()/notify()</code>机制通常是最直接的选择。
                        </p>
                    </div>
                    <div>
                        <h4 class="font-semibold text-gray-800 mb-2 flex items-center">
                            <i class="fas fa-check-circle text-green-500 mr-2"></i> 复杂顺序控制
                        </h4>
                        <p class="text-gray-600">
                            对于需要更复杂顺序控制的场景，可以考虑使用<code>ReentrantLock</code>配合<code>Condition</code>，或者使用有序队列。
                        </p>
                    </div>
                    <div>
                        <h4 class="font-semibold text-gray-800 mb-2 flex items-center">
                            <i class="fas fa-check-circle text-green-500 mr-2"></i> 任务调度
                        </h4>
                        <p class="text-gray-600">
                            如果需要控制任务的执行顺序，线程池配合有序任务队列通常是更好的选择。
                        </p>
                    </div>
                    <div>
                        <h4 class="font-semibold text-gray-800 mb-2 flex items-center">
                            <i class="fas fa-check-circle text-green-500 mr-2"></i> 性能考虑
                        </h4>
                        <p class="text-gray-600">
                            在性能敏感的场景中，应当尽量避免使用过多的锁，可以考虑使用无锁数据结构或原子变量。
                        </p>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-12">
        <div class="container mx-auto px-6 text-center">
            <div class="mb-4">
                <h3 class="text-xl font-bold text-white mb-2">技术小馆</h3>
                <p class="text-gray-400">探索技术之美，分享编程之道</p>
            </div>
            <div class="mb-6">
                <a href="http://www.yuque.com/jtostring" class="text-gray-300 hover:text-white transition duration-300">
                    <i class="fas fa-globe mr-2"></i> http://www.yuque.com/jtostring
                </a>
            </div>
            <div class="text-sm text-gray-500">
                &copy; 2023 技术小馆. 保留所有权利.
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```